package com.yanqu.road.server.cmd.activity.lottery;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ActivityLotteryProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.lottery.ActivityLotteryModule;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_ACTIVITY_LOTTERY_DRAW_HIDE_BOX_FROM_CROSS, desc = "判断能否抽隐藏款  跨服返回")
public class ActivityLotteryDrawCmdFromCross extends AbstractCommand {

    boolean canHide = false;
    int activityId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ActivityLotteryProto.CrossActivityLotteryDrawHideBoxRespMsg reqMsg = ActivityLotteryProto.CrossActivityLotteryDrawHideBoxRespMsg.parseFrom(packet.getBytes());
        ret = reqMsg.getRet();
        if (ret == 0) {
            canHide = reqMsg.getIsHide();
        }
        activityId = reqMsg.getActivityId();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if(ret != 0){
            return;
        }
        ret = player.getModule(ActivityLotteryModule.class).drawBoxFromCross(activityId, canHide);
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            ActivityLotteryProto.ActivityLotteryDrawRespMsg.Builder builder = ActivityLotteryProto.ActivityLotteryDrawRespMsg.newBuilder();
            builder.setRet(ret);
            builder.setActivityId(activityId);
            player.sendPacket(ClientProtocol.U_ACTIVITY_LOTTERY_DRAW, builder);
        }
    }
}
